#pragma once
#include <QString>
#include <functional>
#include <QNetworkReply>
class HttpUtils
{
public:
	static void get(const QString& url, std::function<void(QString&)>& onFinished)
	{
		QNetworkAccessManager net;
		QUrl qUrl(url);
		QNetworkRequest request(qUrl);
		QNetworkReply* reply = net.get(request);

		QObject::connect(reply, &QNetworkReply::finished, [&reply, &onFinished]() {
            if (reply->error() == QNetworkReply::NoError) {
                qDebug() << "success";
            }
            QByteArray array = reply->readAll();
            QString response = QString::fromUtf8(array);
            onFinished(response);
            reply->deleteLater();
		});
	}
};